#pragma once

#include <boost/optional.hpp>
#include <boost/shared_ptr.hpp>
#include <string>
#include <vector>

namespace Broady {

class PCap
{
public:
	struct Address
	{
		boost::optional<unsigned int> m_addr;
		boost::optional<unsigned int> m_netmask;

		Address( void );
		Address( boost::optional<unsigned int> addr, boost::optional<unsigned int> netmask );
	};

	typedef std::vector<Address> AddressList;

	struct Device
	{
		std::string m_name;
		std::string m_description;
		std::vector<Address> m_addresses;

		Device( void );
		Device( const char* const name, const char* const description, const AddressList& addresses );
	};

	typedef boost::shared_ptr<Device> DevicePtr;
	typedef std::vector<DevicePtr> DevicePtrList;
	typedef void ( *HandlerProc )( void*, const char*, const char* );

public:
	~PCap( void );
	static boost::shared_ptr<PCap> Open( DevicePtr dev );
	static boost::optional<DevicePtrList> ListDevices( void );
	static DevicePtr ChooseDevice( const char* const caption, const DevicePtrList& devices );
	boost::optional<bool> SetNonBlock( bool nonblock );
	boost::optional<unsigned int> Dispatch( int maxPackets, HandlerProc handler, void* userData );

private:
	PCap( void* handle );

	void* m_handle;
};

} // namespace
